package com.zgz.underwrite.action;

import java.util.Collections;
import java.util.List;

import com.zgz.underwrite.dao.CoverageDao;
import com.zgz.underwrite.model.Coverage;

public class CoverageAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7483807446163139142L;
	
	private Coverage coverage;
	
	private CoverageDao coverageDao;
	
	
	public String newCoverage(){
		try {
			this.coverageDao.save(this.coverage);
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ERROR;
	}
	
	public String findAllCoverage(){
		List<Coverage> coverages = Collections.emptyList();
		try {
			coverages = (List<Coverage>) this.coverageDao.getAll();
			super.request.getSession().setAttribute("coverages", coverages);
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ERROR;
	}
	
	public String deleteCoverage(){
		try {
			this.coverageDao.delete(this.coverage);
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ERROR;
	}
	
	public String editCoverage(){
		try {
			this.coverageDao.update(this.coverage);
			return INPUT;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ERROR;
	}
	

	public void setCoverage(Coverage coverage) {
		this.coverage = coverage;
	}

	public Coverage getCoverage() {
		return coverage;
	}

	public void setCoverageDao(CoverageDao coverageDao) {
		this.coverageDao = coverageDao;
	}

	public CoverageDao getCoverageDao() {
		return coverageDao;
	}

}
